Imports System.Data
Imports System.Data.SqlClient

Public Class Test_Stored_Procedure


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'open database
        Dim strconnection As String
        strconnection = My.Settings.DocRegData2ConnectionString.ToString
        Dim cn As SqlConnection = New SqlConnection(strconnection)
        cn.Open()

        'stel parameter in
        Dim BedrijvenID As Integer = 2

        'stel command in (stored procedure)
        Dim cmd As New SqlCommand("GetInfoTekeningen", cn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@BedrijvenID", BedrijvenID)

        'voer de command uit
        cmd.ExecuteNonQuery()

        'sluit de database
        cn.Close()

        'Create a new SqlDataAdapter  
        Dim objdataAdapter As New SqlDataAdapter()

        'Set the SelectCommand property of our adapter  
        objdataAdapter.SelectCommand = cmd

        'Create a new DataSet  
        Dim objdatasetTekeningen As New DataSet

        'Fill the DataSet using the SqlDataAdapter  
        objdataAdapter.Fill(objdatasetTekeningen, "Tekeningenbedrijven")

        Dim objbindingsource As New BindingSource
        objbindingsource.DataSource = objdatasetTekeningen.Tables("Tekeningenbedrijven")

        DataGridView1.AutoGenerateColumns = True
        DataGridView1.DataSource = objbindingsource


    End Sub
End Class